package game;

import java.io.IOException;
import java.io.InputStream;

import javax.microedition.lcdui.*;
import javax.microedition.m2g.*;
import org.w3c.dom.svg.SVGElement;

/**
 * This class handles all things which have to be done for a pretty nice start_level_splashscreen!
 * @author Gustav
 * @since 29.5.2010
 */
public class Start_Level {
    private SVGImage svgImage;
    private SVGAnimator svgAnimator;
    private Canvas svgCanvas;

    /**
     * One-Time initialization
     */
    public Start_Level(){
        InputStream is = getClass().getResourceAsStream("/start.svg");
        try {
                 svgImage = (SVGImage)SVGImage.createImage(is, null);
        } catch (IOException e) {
                e.printStackTrace();
            System.out.println("Could not load image!");
        }
        svgAnimator = SVGAnimator.createAnimator(svgImage);
        svgCanvas = (Canvas)svgAnimator.getTargetComponent();
        svgCanvas.setFullScreenMode(true);
    }

    /**
     * Wanna see the splash? You wanna see the splash!
     */
    public void start(){
        svgAnimator.play();
        Display.getDisplay(LUMM2_Canvas.midlet).setCurrent(svgCanvas);
        SVGElement e = (SVGElement)svgImage.getDocument().getElementById("text");
        e.setTrait("#text", ""+(LUMM2_Game.arena.getCurrentLevel()));
        ( new Thread(){public void run() {
                try{
                        Thread.sleep(3000);
                }
                catch(Exception e){}
                svgAnimator.stop();
                LUMM2_Game.currentGameState = LUMM2_Game.PLAY;
                Display.getDisplay(LUMM2_Canvas.midlet).setCurrent(LUMM2_Midlet.pc);
        }}).start();
    }
}
